#!/bin/bash

# Init file for the running gm4lin as a daemon
#
# description: 	This is a userland driver for the GM45 and\
#		GM10 radiation detectors. It can send \
#		collected data to a mysql database or \
#		to a log file. Error messages can be \
#		logged by syslog somewhere like \
#		/var/log/daemon/errors
#
# processname: gm4lin

# source function library
. /etc/rc.d/init.d/functions

RETVAL=0
DRIVER=gm4lin

case "$1" in
  start)
	 gprintf "Starting $DRIVER radiation detectors driver: "
	 # this line is for P5
	 $DRIVER -n 2 -p -s 3 --no-file-log --mysql bicron@gateway:lab_data:radiation:gm45_ --port 3308 --passwd cdsinc --uid 502 --daemon --syslog
	 RETVAL_P5=$?
	 # this line is for P8
	 $DRIVER -n 2 -p -s 1 --no-file-log --mysql bicron@gateway:lab_data:radiation:gm45_ --port 3306 --passwd cdsinc --uid 502 --daemon --syslog
	 RETVAL_P8=$?
	 RETVAL=$(($RETVAL_P5 || $RETVAL_P8))

	 echo
        ;;
  stop)
        gprintf "Stopping $DRIVER radiation detectors driver: "
        killproc $DRIVER
        RETVAL=$?
	
        echo
        
        ;;
  restart)
        $0 stop
        $0 start
	RETVAL=$?
        ;;
  status)
        status $DRIVER
	RETVAL=$?
        ;;
  *)
	gprintf "Usage: $DRIVER {start|stop|restart|status}\n"
	exit 1
esac

exit $RETVAL
